package org.lemon.transport.context.service;

import org.lemon.transport.context.service.queue.discovery.QueueRoutingInfo;
import org.lemon.transport.context.service.queue.discovery.QueueRoutingInfoService;
import org.server.transport.gen.TransportProto;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class TransportQueueRoutingInfoService implements QueueRoutingInfoService {

    private final TransportService transportService;

    public TransportQueueRoutingInfoService(@Lazy TransportService transportService) {
        this.transportService = transportService;
    }

    @Override
    public List<QueueRoutingInfo> getAllQueuesRoutingInfo() {

        TransportProto.GetAllQueueRoutingInfoRequestMsg msg = TransportProto.GetAllQueueRoutingInfoRequestMsg.newBuilder().build();
        return transportService.getQueueRoutingInfo(msg)
                .stream().map(QueueRoutingInfo::new)
                .collect(Collectors.toList());
    }
}
